import pytest
from loguru import logger

from base.base_assert import current_page
from base.base_driver import DRIVER
from page.page_main import MainPage

MAIN = MainPage()


@pytest.fixture(scope="session",autouse=True)
def app():
    if DRIVER.is_app_installed("com.xiaomi.shop") is False:
        logger.info("应用未安装，开始安装")
        # DRIVER.install_app("com.xiaomi.shop")
    yield
    logger.info("卸载小米商城")
    # DRIVER.remove_app("com.xiaomi.shop")


@pytest.fixture(scope="function",autouse=True)
def start_driver():
    DRIVER.activate_app("com.xiaomi.shop")
    logger.info(f"{'!'*20} 开始执行用例 {'!'*20}")
    yield
    logger.info(f"{'!'*20} 用例执行完毕 {'!'*20}")
    DRIVER.terminate_app("com.xiaomi.shop")



# @pytest.fixture(scope="function",autouse=True)
# def start_case():
#     logger.info(f"{'!'*20} 开始执行用例 {'!'*20}")
#     while current_page() != ".activity.MainTabActivity":
#         DRIVER.back()
#     yield
#     logger.info(f"{'!'*20} 用例执行完毕 {'!'*20}")
#

